package dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageModel<T> {
    //上一页
    int pre;
    //下一页
    int next;
    //当前页码数
    int pageNow;
    //当前页显示数据条数
    int pageSize = 4;
    //总页数
    int totalPage;
    //总数据量
    int count;
    //存放数据
    List<T> list;

    public PageModel(int pageNow, int pageSize, int count) {

        //页面越界问题
        this.pageNow = pageNow;
        this.pageSize = pageSize;
        this.count = count;
        //求页面的总页数
        this.totalPage = this.count % pageSize == 0 ? this.count / this.pageSize : this.count / this.pageSize + 1;
        //判断页面越界
        //限制最小页面数最低为1
        this.pageNow = Math.max(this.pageNow, 1);
        //限制最大页数为总页数
        this.pageNow = Math.min(this.pageNow, this.totalPage);

    }
}
